home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
DOUBLEDE
/
WINDOWS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-28
|
11KB
|
459 lines
#include "shell.h"
/*====================================================================
makewindows()
create some application windows. "windows" is a global WindowPtr
array for general application use. the window definition proc
is defined in shell.h. clip_window is a window to display the
contents of the clipboard.
global definition NUMWINDOWS (shell.h) indicates how many
application windows to create
====================================================================*/
makewindows()
{
#define WINDOWWIDTH 160
Rect wRect;
Rect cRect;
int index;
Str255 wTitle;
Str255 aStr;
wRect = screenBits.bounds;
wRect.top = wRect.bottom - 80;
InsetRect(&wRect,12,12);
SetPort(clip_window = NewWindow(NIL,&wRect,"\pClipboard",FALSE,8,-1L,TRUE,0));
TextFont(4);
TextSize(9);
centerwindow(clip_window,&wRect);
SetRect(&cRect,0,0,1,1);
SetRect(&wRect,10,50,180,200);
for(index=0; index<NUMWINDOWS; index++){
/*
build window title from index
*/
strcpy(wTitle,"Untitled ");
NumToString((long)index+1L,aStr);
PtoCstr((char *)aStr);
strcat(wTitle,aStr);
CtoPstr((char *)wTitle);
/*
make & show the window(s)
*/
SetPort(windows[index] = NewWindow(NIL,&wRect,wTitle,FALSE,WINDOWDEFPROC,-1L,TRUE,0));
TextFont(4);
TextSize(9);
TextFace(0);
TextMode(srcCopy);
ShowWindow(windows[index]);
demoButton[index] = NewControl(windows[index],&cRect,"\pDemo",TRUE,0,0,1,0,0);
posbutton(index);
demo_double[index] = 3.14159265;
/*
offset the rectangle for the next window
*/
OffsetRect(&wRect,16,16);
}
}
/*====================================================================
handleactivate()
called on an activate/deactivate event.
====================================================================*/
handleactivate()
{
WindowPtr eventWindow;
SetPort(eventWindow = (WindowPtr)event.message);
/*
is it one of our windows?
*/
if ((w_index = ourwindow(eventWindow)) >= 0){
/*
DrawGrowIcon(WindowPtr) will correctly draw the
grow icon whether the window is being activated
or deactivated
*/
DrawGrowIcon(eventWindow);
if (BitAnd(event.modifiers,activeFlag != 0)){
/* what to do on activate */
HiliteControl(demoButton[w_index],ACTIVE);
if (BitAnd(event.modifiers,changeFlag) != 0){
/*
what to do when coming from a DA
or coming from another application
running under MultiFinder
*/
}
}
else{
/* what to do on deactivate */
HiliteControl(demoButton[w_index],INACTIVE);
if (BitAnd(event.modifiers,changeFlag) != 0){
/*
what to do when leaving to a DA
or going to another application
running under MultiFinder
*/
}
}
}
if ( (eventWindow==clip_window) ){
/*
window involved is our clipboard window
*/
DrawGrowIcon(eventWindow);
if (BitAnd(event.modifiers,activeFlag != 0)){
/*
what to do if clipboard is being made active,
clipboard changes are handled elsewhere from
selections made in the "Edit" menu
*/
}
else{
/*
what to do if clipboard is being deactivated
*/
}
}
}
/*====================================================================
handleupdate(WindowPtr)
called on an update event. If it is one of our application
windows, clip drawing to inside the scroll bar areas, and do
whatever drawing is needed.
if clipboard window needs updating, call updateclipboard()
====================================================================*/
handleupdate(thisPort)
GrafPtr thisPort;
{
GrafPtr tempPort;
Rect dummyRect;
Str255 aStr;
GetPort(&tempPort);
SetPort(thisPort);
if ((w_index = ourwindow(thisPort)) >= 0){
BeginUpdate(thisPort);
EraseRect(&thisPort->portRect);
DrawGrowIcon(thisPort);
DrawControls(thisPort);
/*
clip drawing to _exclude_ the scroll bar areas, and the
grow icon area
*/
dummyRect = thisPort->portRect;
dummyRect.right -= SCROLLBARWIDTH;
dummyRect.bottom -= SCROLLBARWIDTH;
ClipRect(&dummyRect);
/*
our drawing routine....
*/
strcpy(aStr,"\pValue = ");
MoveTo(4,15);
DrawString(aStr);
double_2_cString(&demo_double[w_index],FIXEDDECIMAL,8,aStr);
DrawText(aStr,0,strlen(aStr));
/*
reset clipping to an arbitrarily large rectangle
*/
SetRect(&dummyRect,-32700,-32700,32700,32700);
ClipRect(&dummyRect);
EndUpdate(thisPort);
}
if (thisPort==clip_window)
updateclipboard();
SetPort(tempPort);
}
/*====================================================================
drawGIcon(WindowPtr)
draws only the grow icon, not the scroll bar lines. clips
drawing to the rectangle of the grow icon, then calls
DrawGrowIcon(WindowPtr)
====================================================================*/
drawGIcon(theWindow)
WindowPtr theWindow;
{
RgnHandle oldClip;
GrafPtr tempPort;
Rect r;
GetPort(&tempPort);
SetPort(theWindow);
/*
save the current clip region in "oldClip"
*/
oldClip = NewRgn();
GetClip(oldClip);
/*
clip drawing to grow icon area
*/
r = theWindow->portRect;
r.top = r.bottom - 15;
r.left = r.right - 15;
ClipRect(&r);
DrawGrowIcon(theWindow);
/*
restore previous clipping, and dispose local RgnHandle
*/
SetClip(oldClip);
DisposeRgn(oldClip);
SetPort(tempPort);
}
/*====================================================================
dodrag(Point,WindowPtr)
drag a window around in the screen_rect.
====================================================================*/
dodrag(aPoint,eventWindow)
Point aPoint;
WindowPtr eventWindow;
{
/*
check to see if window is not frontmost, and that the command
key is not down. If both of those are true, then bring the
window to front via SelectWindow(WindowPtr). If the window
is not frontmost and the command key _is_ down, then we can't
bring it to front since command dragging should not select the
window
*/
if ( (FrontWindow() != eventWindow) && ((event.modifiers & cmdKey) == 0) )
SelectWindow(eventWindow);
else
DragWindow(eventWindow, aPoint, &screen_rect);
}
/*====================================================================
docontent(Point,WindowPtr)
a click occurred in the window indicated in the WindowPtr parameter.
the Point is in global coordinates, and must be converted to local
window coordinates to determine what area of the window content was
hit.
====================================================================*/
docontent(aPoint,eventWindow)
Point aPoint;
WindowPtr eventWindow;
{
ControlHandle theControl;
int Part;
if (FrontWindow() != eventWindow)
SelectWindow(eventWindow);
else{
GlobalToLocal(&aPoint);
if ((w_index = ourwindow(eventWindow)) >= 0){
Part = FindControl(aPoint,eventWindow,&theControl);
if (theControl == demoButton[w_index]){
if (Part = inButton){
Part = TrackControl(theControl,aPoint,NIL);
if (Part == inButton){
do_demo(w_index);
}
}
}
}
}
}
/*====================================================================
InvalHScrollArea(WindowPtr)
Invalidates the horizontal scroll bar area of the window indicated
by the WindowPtr parameter. forces an update event.
====================================================================*/
InvalHScrollArea(whichWindow)
WindowPtr whichWindow;
{
GrafPtr tp;
Rect r;
GetPort(&tp);
SetPort(whichWindow);
r = whichWindow->portRect;
r.top = r.bottom - SCROLLBARWIDTH;
InvalRect(&r);
SetPort(tp);
}
/*====================================================================
InvalVScrollArea(WindowPtr)
Invalidates the vertical scroll bar area of the window indicated
by the WindowPtr parameter. forces an update event.
====================================================================*/
InvalVScrollArea(whichWindow)
WindowPtr whichWindow;
{
GrafPtr tp;
Rect r;
GetPort(&tp);
SetPort(whichWindow);
r = whichWindow->portRect;
r.left = r.right - SCROLLBARWIDTH;
InvalRect(&r);
SetPort(tp);
}
/*====================================================================
dogrow(Point,WindowPtr)
resize the window indicated by the WindowPtr parameter.
====================================================================*/
dogrow(aPoint,eventWindow)
Point aPoint;
WindowPtr eventWindow;
{
register int index;
int newWidth;
int newHeight;
long newSize;
Rect limitRect;
if (FrontWindow() != eventWindow)
SelectWindow(eventWindow);
else{
if ((w_index = ourwindow(eventWindow)) >= 0){
/*
smallest size is 80h x 40v,
largest size is arbitrarily large
*/
SetRect(&limitRect,80,40,32000,32000);
newSize = GrowWindow(eventWindow,aPoint,&limitRect);
if (newSize != NIL){
newWidth = LoWord(newSize);
newHeight = HiWord(newSize);
InvalHScrollArea(eventWindow);
InvalVScrollArea(eventWindow);
SizeWindow(eventWindow,newWidth,newHeight,TRUE);
InvalRect(&eventWindow->portRect);
posbutton(w_index);
}
}
if (eventWindow == clip_window){
SetRect(&limitRect,80,40,32000,32000);
newSize = GrowWindow(eventWindow,aPoint,&limitRect);
if (newSize != NIL){
InvalHScrollArea(eventWindow);
InvalVScrollArea(eventWindow);
newWidth = LoWord(newSize);
newHeight = HiWord(newSize);
SizeWindow(eventWindow,newWidth,newHeight,TRUE);
InvalRect(&eventWindow->portRect);
}
}
}
}
/*====================================================================
dogoaway(Point,WindowPtr)
user clicked in the goaway box of one of our windows, track the
click to allow them to change their minds before releasing the
mouse button
if global boolean "quit_on_wind_close" is TRUE, then this will
cause the application to quit.
====================================================================*/
dogoaway(aPoint,eventWindow)
Point aPoint;
WindowPtr eventWindow;
{
if (TrackGoAway(eventWindow,aPoint)){
if ((w_index = ourwindow(eventWindow)) >= 0){
quitting = quit_on_wind_close;
HideWindow(eventWindow);
}
}
if (eventWindow==clip_window)
showclipwindow();
}
/*====================================================================
ourwindow(WindowPtr)
if the window indicated by the WindowPtr parameter is in our
array of application windows, returns the index into the array
for that window, from 0..NUNWINDOWS-1.
if the window is not in the array, returns -1
====================================================================*/
ourwindow(theWindow)
WindowPtr theWindow;
{
register int index;
for(index=0;index<NUMWINDOWS;index++)
if (theWindow==windows[index])
return(index);
return(-1);
}